package apihomework;

import java.util.Random;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        String line ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        String code ="";
        for(int i=0;i<4;i++){
            int index = random.nextInt(line.length());
            char c = line.charAt(index);
            code+=c;
        }
        System.out.println("验证码为:"+code);

        while (true){
            System.out.print("请输入验证码:");
            Scanner scan = new Scanner(System.in);
            String s = scan.nextLine();
            if(code.equalsIgnoreCase(s)){
                System.out.println("验证成功!");
                break;
            }else {
                System.out.println("验证失败!");
            }
        }
    }
}
